import { createStore, applyMiddleware } from "redux";
import reducer from './reducer'
import logger from 'redux-logger'
import thunk from 'redux-thunk'


import { persistStore, persistReducer } from 'redux-persist'
import storage from 'redux-persist/lib/storage' //默认存储在localStorage中
// import storage from 'redux-persist/lib/storage/session' //存储在sessionStorage中


//createStore(纯函数,应用插件)  创建一个唯一的store( 数据仓库 )
//applyMiddleware() 应用其他第三方中间件到redux中
//logger 本质是函数,负责打印日志( 每当store中的数据发生变化,就会自动打印日志 )
//生成一个持久化的reducer
var persistedReducer = persistReducer(
    { key: 'redux', storage },
    reducer,
)

//创建store
var store = createStore(persistedReducer, applyMiddleware(thunk, logger,))

//生成一个持久化的store
export var persistor = persistStore(store);

export default store;